package zsc.ruanc.practicaltraining.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zsc.ruanc.practicaltraining.exception.ApiException;
import zsc.ruanc.practicaltraining.mapper.Redis;
import zsc.ruanc.practicaltraining.service.RedisService;

@Service
public class RedisSerivceImpl implements RedisService {

    @Autowired
    private Redis redis;

    @Override
    public void set(String key, Object value) {
        redis.set(key, value);
    }

    @Override
    public void set(String key, Object value, int time) {
        redis.set(key, value, time);
    }

    @Override
    public Object get(String key) {
        return redis.get(key);
    }

    @Override
    public boolean delete(String key) {
        return redis.delete(key);
    }

    @Override
    public boolean refresh(String key, int time) {
        redis.refresh(key, time);
        return true;
    }

    @Override
    public boolean verificationCode(String key, int code) {
        Object o = redis.get(key);
        if (o == null) {
            throw new ApiException(-7);
        }
        int x = (int )o;
        if (x == code) {
//            redis.deleteMailCode(email);
            return true;
        }
        throw new ApiException(-6);
    }
}
